package cn.com.coding.app;

import cn.com.coding.common.lang.ResT;
import cn.com.coding.common.utils.PageUtil;
import cn.com.coding.system.domin.UserPurseEntity;
import cn.com.coding.system.service.UserPurseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;


/**
 * 钱包（飞猫币）
 *
 * @author mxz
 */
@RestController
@RequestMapping("cat/userpurse")
public class UserPurseController {
    @Autowired
    private UserPurseService userPurseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResT list(@RequestParam Map<String, Object> params) {
        PageUtil page = userPurseService.queryPage(params);

        return ResT.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{pid}")
    public ResT info(@PathVariable("pid") String pid) {
        UserPurseEntity userPurse = userPurseService.getById(pid);

        return ResT.ok().put("userPurse", userPurse);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResT save(@RequestBody UserPurseEntity userPurse) {
        userPurseService.save(userPurse);

        return ResT.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResT update(@RequestBody UserPurseEntity userPurse) {
        userPurseService.updateById(userPurse);

        return ResT.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResT delete(@RequestBody String[] pids) {
        userPurseService.removeByIds(Arrays.asList(pids));

        return ResT.ok();
    }

}
